/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React, { useEffect, useRef } from 'react';
import { message } from 'antd';
import DragTable from '@/components/DragTable';
import ProTable from '@ant-design/pro-table';
import type { ActionType } from '@ant-design/pro-table';
import { getMarketSmsList } from '@/services/ad/marketingSms/index';
import { logColumns } from '../../utils/ad.marketingSms';

const Index = (props: { show: boolean }) => {
  const { show } = props;
  const actionRef = useRef<ActionType>();

  const queryTable = async (values: any) => {
    const { current: page_num, pageSize: page_size } = values;
    const { code, data, msg } = await getMarketSmsList({ page_num, page_size });
    if (code == 0) {
      return {
        data: data.list,
        total: data.total,
      };
    } else {
      message.error(msg);
      return { data: [] };
    }
  };

  useEffect(() => {
    if (show) {
      actionRef.current?.reload();
    }
  }, [show]);
  return (
    <DragTable>
      <ProTable
        rowKey='id'
        actionRef={actionRef}
        toolBarRender={false}
        columns={logColumns}
        request={queryTable}
        scroll={{ x: 1200 }}
        search={false}
      />
    </DragTable>
  );
};

export default Index;
